/*
 *  Copyright (C) Research In Motion Limited 2010. All rights reserved.
 *  Copyright (C) 2010 Joone Hur <joone@kldp.org>
 *  Copyright (C) 2009 Google Inc. All rights reserved.
 *  Copyright (C) 2011 Igalia S.L.
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include "config.h"
#include "DumpRenderTreeSupportManx.h"

#include "APICast.h"
#include "accessibility/AXObjectCache.h"
#include "accessibility/AccessibilityObject.h"
#include "AnimationController.h"
// #include "CSSComputedStyleDeclaration.h"
#include "DOMWrapperWorld.h"
#include "Document.h"
#include <Documentloader.h>
#include "EditorClientManx.h"
#include "Element.h"
#include "FocusController.h"
#include "FrameLoaderClientManx.h"
#include "FrameTree.h"
#include "WebCore\bindings\js\GCController.h"
// #include "GeolocationClientMock.h"
// #include "GeolocationController.h"
// #include "GeolocationError.h"
// #include "GeolocationPosition.h"
// #include "GraphicsContext.h"
// #include "HTMLInputElement.h"
// #include "JSCSSStyleDeclaration.h"
#include "JSDOMWindow.h"
#include "JSDocument.h"
#include "JSElement.h"
#include "JSLock.h"
#include "JSNodeList.h"
#include "JSValue.h"
#include "NodeList.h"
#include "PageGroup.h"
#include "PlatformString.h"
#include "PrintContext.h"
// #include "RenderListItem.h"
#include "RenderTreeAsText.h"
// #include "RenderView.h"
// #include "SchemeRegistry.h"
// #include "SecurityOrigin.h"
// #include "SecurityPolicy.h"
// #include "Settings.h"
// #include "TextIterator.h"
// #include "WebKitAccessibleWrapperAtk.h"
// #include "WebKitMutationObserver.h"
// #include "WorkerThread.h"
// #include "webkitglobalsprivate.h"
#include "Frame.h"
// #include "Frameprivate.h"
#include <JavaScriptCore/APICast.h>

using namespace JSC;
using namespace WebCore;
using namespace WebKit;

bool DumpRenderTreeSupportManx::s_drtRun = false;
bool DumpRenderTreeSupportManx::s_linksIncludedInTabChain = true;
bool DumpRenderTreeSupportManx::s_selectTrailingWhitespaceEnabled = false;

DumpRenderTreeSupportManx::DumpRenderTreeSupportManx()
{
}

DumpRenderTreeSupportManx::~DumpRenderTreeSupportManx()
{
}

void DumpRenderTreeSupportManx::setDumpRenderTreeModeEnabled(bool enabled)
{
    s_drtRun = enabled;
}

bool DumpRenderTreeSupportManx::dumpRenderTreeModeEnabled()
{
    return s_drtRun;
}
void DumpRenderTreeSupportManx::setLinksIncludedInFocusChain(bool enabled)
{
    s_linksIncludedInTabChain = enabled;
}

bool DumpRenderTreeSupportManx::linksIncludedInFocusChain()
{
    return s_linksIncludedInTabChain;
}

void DumpRenderTreeSupportManx::setSelectTrailingWhitespaceEnabled(bool enabled)
{
    s_selectTrailingWhitespaceEnabled = enabled;
}

bool DumpRenderTreeSupportManx::selectTrailingWhitespaceEnabled()
{
    return s_selectTrailingWhitespaceEnabled;
}
list<Frame*> DumpRenderTreeSupportManx::getFrameChildren(const Frame* frame)
{
    if (!frame)
        return;

    list<Frame*> children;
    for (Frame* child = frame->tree()->firstChild(); child; child = child->tree()->nextSibling()) {
        FrameLoader* loader = child->loader();
        FrameLoaderClientManx* client = static_cast<FrameLoaderClientManx*>(loader->client());
        if (client)
            children.push_back(client->frame());
            // children = g_slist_append(children, client->frame();//webFrame());
    }

    return children;
}
/**
 * getGlobalContext :
 * @frame: a #Frame
 *
 * Gets the global JavaScript execution context. Use this function to bridge
 * between the WebKit and JavaScriptCore APIs.
 *
 * Return value: (transfer none): the global JavaScript context
 */
// JSGlobalContextRef DumpRenderTreeSupportManx::getGlobalContext(const Frame* frame)
// {
//    if (!frame)
//        return 0;
//    return toGlobalRef(frame->script()->globalObject(mainThreadNormalWorld()->globalExec()));
// }

/**
 * getInnerText:
 * @frame: a #Frame
 *
 * Return value: inner text of @frame
 */
CString DumpRenderTreeSupportManx::getInnerText(Frame* frame)
{

    Frame* coreFrame = frame;
    if (!coreFrame)
        return CString("");

    FrameView* view = coreFrame->view();
    if (view && view->layoutPending())
        view->layout();

    Element* documentElement = coreFrame->document()->documentElement();
    if (!documentElement)
        return CString("");
    return documentElement->innerText().utf8();
}


/**
 * dumpRenderTree:
 * @frame: a #Frame
 *
 * Return value: Non-recursive render tree dump of @frame
 */
CString DumpRenderTreeSupportManx::dumpRenderTree(Frame* frame)
{

    Frame* coreFrame = frame;
    if (!coreFrame)
        return CString("");

    FrameView* view = coreFrame->view();

    if (view && view->layoutPending())
        view->layout();

    return externalRepresentation(coreFrame).utf8();
}


CString DumpRenderTreeSupportManx::getFrameName(const Frame* frame)
{
    if (!frame)
        return CString("");
    CString frameName = frame->tree()->uniqueName().string().utf8();

    return frame->tree()->uniqueName().string().utf8();
}
CString DumpRenderTreeSupportManx::getResponseMimeType(const Frame* frame)
{
    if (!frame) 
        return CString("");

    WebCore::DocumentLoader* docLoader = frame->loader()->documentLoader();
    String mimeType = docLoader->responseMIMEType();

    return mimeType.utf8();
}
/**
 * counterValueForElementById:
 * @frame: a #Frame
 * @id: an element ID string
 *
 * Return value: The counter value of element @id in @frame
 */
CString DumpRenderTreeSupportManx::counterValueForElementById(Frame* frame, const char* id)
{

    Frame* coreFrame = frame;
    if (!coreFrame)
        return CString();

    Element* coreElement = coreFrame->document()->getElementById(AtomicString(id));
    if (!coreElement)
        return CString();

    return counterValueForElement(coreElement).utf8().data();
}

/**
 * numberForElementById
 * @frame: a #Frame
 * @id: an element ID string
 * @pageWidth: width of a page
 * @pageHeight: height of a page
 *
 * Return value: The number of page where the specified element will be put
 */
int DumpRenderTreeSupportManx::pageNumberForElementById(Frame* frame, const char* id, float pageWidth, float pageHeight)
{

    Frame* coreFrame = frame;
    if (!coreFrame)
        return -1;

    Element* coreElement = coreFrame->document()->getElementById(AtomicString(id));
    if (!coreElement)
        return -1;
    return PrintContext::pageNumberForElement(coreElement, FloatSize(pageWidth, pageHeight));
}

/**
 * numberOfPagesForFrame
 * @frame: a #Frame
 * @pageWidth: width of a page
 * @pageHeight: height of a page
 *
 * Return value: The number of pages to be printed.
 */
// int DumpRenderTreeSupportManx::numberOfPagesForFrame(Frame* frame, float pageWidth, float pageHeight)
// {
//    g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), 0);
//
//    Frame* coreFrame = core(frame);
//    if (!coreFrame)
//        return -1;
//
//    return PrintContext::numberOfPages(coreFrame, FloatSize(pageWidth, pageHeight));
// }

/**
 * pageProperty
 * @frame: a #Frame
 * @propertyName: name of a property
 * @pageNumber: number of a page 
 *
 * Return value: The value of the given property name.
 */
// CString DumpRenderTreeSupportManx::pageProperty(Frame* frame, const char* propertyName, int pageNumber)
// {
//    g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), CString());
//
//    Frame* coreFrame = core(frame);
//    if (!coreFrame)
//        return CString();
//
//    return PrintContext::pageProperty(coreFrame, propertyName, pageNumber).utf8();
// }

/**
 * isPageBoxVisible
 * @frame: a #Frame
 * @pageNumber: number of a page 
 *
 * Return value: TRUE if a page box is visible. 
 */
// bool DumpRenderTreeSupportManx::isPageBoxVisible(Frame* frame, int pageNumber)
// {
//    g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), false);
//
//    Frame* coreFrame = core(frame);
//    if (!coreFrame)
//        return false;
//    return coreFrame->document()->isPageBoxVisible(pageNumber); 
// }

/**
 * pageSizeAndMarginsInPixels
 * @frame: a #Frame
 * @pageNumber: number of a page 
 * @width: width of a page
 * @height: height of a page
 * @marginTop: top margin of a page
 * @marginRight: right margin of a page
 * @marginBottom: bottom margin of a page
 * @marginLeft: left margin of a page
 *
 * Return value: The value of page size and margin.
 */
// CString DumpRenderTreeSupportManx::pageSizeAndMarginsInPixels(Frame* frame, int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft)
// {
//    g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), CString());
//
//    Frame* coreFrame = core(frame);
//    if (!coreFrame)
//        return CString();
//
//    return PrintContext::pageSizeAndMarginsInPixels(coreFrame, pageNumber, width, height, marginTop, marginRight, marginBottom, marginLeft).utf8();
// }

/**
 * addUserStyleSheet
 * @frame: a #Frame
 * @sourceCode: code of a user stylesheet
 *
 */
// void DumpRenderTreeSupportManx::addUserStyleSheet(Frame* frame, const char* sourceCode, bool allFrames)
// {
//    g_return_if_fail(WEBKIT_IS_WEB_FRAME(frame));
//
//    Frame* coreFrame = core(frame);
//    if (!coreFrame)
//        return;
//
//    WebKitWebView* webView = getViewFromFrame(frame);
//    Page* page = core(webView);
//    page->group().addUserStyleSheetToWorld(mainThreadNormalWorld(), sourceCode, KURL(), nullptr, nullptr, allFrames ? InjectInAllFrames : InjectInTopFrameOnly); 
// }

/**
 * getPendingUnloadEventCount:
 * @frame: a #Frame
 *
 * Return value: number of pending unload events
 */
// guint DumpRenderTreeSupportManx::getPendingUnloadEventCount(Frame* frame)
// {
//    g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), 0);
//
//    return core(frame)->domWindow()->pendingUnloadEventListeners();
// }
//
// bool DumpRenderTreeSupportManx::pauseAnimation(Frame* frame, const char* name, double time, const char* element)
// {
//    ASSERT(core(frame));
//    Element* coreElement = core(frame)->document()->getElementById(AtomicString(element));
//    if (!coreElement || !coreElement->renderer())
//        return false;
//    return core(frame)->animation()->pauseAnimationAtTime(coreElement->renderer(), AtomicString(name), time);
// }
//
// bool DumpRenderTreeSupportManx::pauseTransition(Frame* frame, const char* name, double time, const char* element)
// {
//    ASSERT(core(frame));
//    Element* coreElement = core(frame)->document()->getElementById(AtomicString(element));
//    if (!coreElement || !coreElement->renderer())
//        return false;
//    return core(frame)->animation()->pauseTransitionAtTime(coreElement->renderer(), AtomicString(name), time);
// }
//
// CString DumpRenderTreeSupportManx::markerTextForListItem(Frame* frame, JSContextRef context, JSValueRef nodeObject)
// {
//    JSC::ExecState* exec = toJS(context);
//    Element* element = toElement(toJS(exec, nodeObject));
//    if (!element)
//        return CString();
//
//    return WebCore::markerTextForListItem(element).utf8();
// }
//
// unsigned int DumpRenderTreeSupportManx::numberOfActiveAnimations(Frame* frame)
// {
//    Frame* coreFrame = core(frame);
//    if (!coreFrame)
//        return 0;
//
//    return coreFrame->animation()->numberOfActiveAnimations(coreFrame->document());
// }

// void DumpRenderTreeSupportManx::suspendAnimations(Frame* frame)
// {
//    Frame* coreFrame = core(frame);
//    if (!coreFrame)
//        return;
//
//    return coreFrame->animation()->suspendAnimations();
// }
//
// void DumpRenderTreeSupportManx::resumeAnimations(Frame* frame)
// {
//    Frame* coreFrame = core(frame);
//    if (!coreFrame)
//        return;
//
//    return coreFrame->animation()->resumeAnimations();
// }

void DumpRenderTreeSupportManx::clearMainFrameName(Frame* frame)
{
    if (!frame)
        return;
    frame->tree()->clearName();
}

// AtkObject* DumpRenderTreeSupportManx::getRootAccessibleElement(Frame* frame)
// {
//    g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), 0);
//
// #if HAVE(ACCESSIBILITY)
//    if (!AXObjectCache::accessibilityEnabled())
//        AXObjectCache::enableAccessibility();
//
//    FramePrivate* priv = frame->priv;
//    if (!priv->coreFrame || !priv->coreFrame->document())
//        return 0;
//
//    AtkObject* wrapper =  priv->coreFrame->document()->axObjectCache()->rootObject()->wrapper();
//    if (!wrapper)
//        return 0;
//
//    return wrapper;
// #else
//    return 0;
// #endif
// }
//
// AtkObject* DumpRenderTreeSupportManx::getFocusedAccessibleElement(Frame* frame)
// {
// #if HAVE(ACCESSIBILITY)
//    AtkObject* wrapper = getRootAccessibleElement(frame);
//    if (!wrapper)
//        return 0;
//
//    return webkitAccessibleGetFocusedElement(WEBKIT_ACCESSIBLE(wrapper));
// #else
//    return 0;
// #endif
// }
//
// void DumpRenderTreeSupportManx::executeCoreCommandByName(WebKitWebView* webView, const char* name, const char* value)
// {
//    g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
//    g_return_if_fail(name);
//    g_return_if_fail(value);
//
//    core(webView)->focusController()->focusedOrMainFrame()->editor()->command(name).execute(value);
// }
//
// bool DumpRenderTreeSupportManx::isCommandEnabled(WebKitWebView* webView, const char* name)
// {
//    g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
//    g_return_val_if_fail(name, FALSE);
//
//    return core(webView)->focusController()->focusedOrMainFrame()->editor()->command(name).isEnabled();
// }
//
// void DumpRenderTreeSupportManx::setComposition(WebKitWebView* webView, const char* text, int start, int length)
// {
//    g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
//    g_return_if_fail(text);
//
//    Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
//    if (!frame)
//        return;
//
//    Editor* editor = frame->editor();
//    if (!editor || (!editor->canEdit() && !editor->hasComposition()))
//        return;
//
//    String compositionString = String::fromUTF8(text);
//    Vector<CompositionUnderline> underlines;
//    underlines.append(CompositionUnderline(0, compositionString.length(), Color(0, 0, 0), false));
//    editor->setComposition(compositionString, underlines, start, start + length);
// }
//
// bool DumpRenderTreeSupportManx::hasComposition(WebKitWebView* webView)
// {
//    g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), false);
//    Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
//    if (!frame)
//        return false;
//    Editor* editor = frame->editor();
//    if (!editor)
//        return false;
//
//    return editor->hasComposition();
// }
//
// bool DumpRenderTreeSupportManx::compositionRange(WebKitWebView* webView, int* start, int* length)
// {
//    g_return_val_if_fail(start && length, false);
//    *start = *length = 0;
//
//    g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), false);
//    Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
//    if (!frame)
//        return false;
//
//    Editor* editor = frame->editor();
//    if (!editor || !editor->hasComposition())
//        return false;
//
//    *start = editor->compositionStart();
//    *length = editor->compositionEnd() - *start;
//    return true;
// }

// void DumpRenderTreeSupportManx::confirmComposition(WebKitWebView* webView, const char* text)
// {
//    g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
//
//    Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
//    if (!frame)
//        return;
//
//    Editor* editor = frame->editor();
//    if (!editor)
//        return;
//
//    if (!editor->hasComposition()) {
//        editor->insertText(String::fromUTF8(text), 0);
//        return;
//    }
//    if (text) {
//        editor->confirmComposition(String::fromUTF8(text));
//        return;
//    }
//    editor->confirmComposition();
// }
//
// void DumpRenderTreeSupportManx::doCommand(WebKitWebView* webView, const char* command)
// {
//    g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
//    Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
//    if (!frame)
//        return;
//
//    Editor* editor = frame->editor();
//    if (!editor)
//        return;
//
//    String commandString(command);
//    // Remove ending : here.
//    if (commandString.endsWith(":", true))
//        commandString = commandString.left(commandString.length() - 1);
//
//    // Make the first char in upper case.
//    String firstChar = commandString.left(1);
//    commandString = commandString.right(commandString.length() - 1);
//    firstChar.makeUpper();
//    commandString.insert(firstChar, 0);
//
//    editor->command(commandString).execute();
// }

// bool DumpRenderTreeSupportManx::firstRectForCharacterRange(WebKitWebView* webView, int location, int length, cairo_rectangle_int_t* rect)
// {
//    g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), false);
//    g_return_val_if_fail(rect, false);
//
//    if ((location + length < location) && (location + length))
//        length = 0;
//
//    Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
//    if (!frame)
//        return false;
//
//    Editor* editor = frame->editor();
//    if (!editor)
//        return false;
//
//    RefPtr<Range> range = TextIterator::rangeFromLocationAndLength(frame->selection()->rootEditableElementOrDocumentElement(), location, length);
//    if (!range)
//        return false;
//
//    *rect = editor->firstRectForRange(range.get());
//    return true;
// }

// bool DumpRenderTreeSupportManx::selectedRange(WebKitWebView* webView, int* start, int* length)
// {
//    g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), false);
//    g_return_val_if_fail(start && length, false);
//
//    Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
//    if (!frame)
//        return false;
//
//    RefPtr<Range> range = frame->selection()->toNormalizedRange().get();
//    if (!range)
//        return false;
//
//    Element* selectionRoot = frame->selection()->rootEditableElement();
//    Element* scope = selectionRoot ? selectionRoot : frame->document()->documentElement();
//
//    RefPtr<Range> testRange = Range::create(scope->document(), scope, 0, range->startContainer(), range->startOffset());
//    ASSERT(testRange->startContainer() == scope);
//    *start = TextIterator::rangeLength(testRange.get());
//
//    ExceptionCode ec;
//    testRange->setEnd(range->endContainer(), range->endOffset(), ec);
//    ASSERT(testRange->startContainer() == scope);
//    *length = TextIterator::rangeLength(testRange.get());
//
//    return true;
// }
//
// void DumpRenderTreeSupportManx::setDefersLoading(WebKitWebView* webView, bool defers)
// {
//    core(webView)->setDefersLoading(defers);
// }
//
// void DumpRenderTreeSupportManx::setSmartInsertDeleteEnabled(WebKitWebView* webView, bool enabled)
// {
//    g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
//    g_return_if_fail(webView);
//
//    WebKit::EditorClient* client = static_cast<WebKit::EditorClient*>(core(webView)->editorClient());
//    client->setSmartInsertDeleteEnabled(enabled);
// }
//
// void DumpRenderTreeSupportManx::whiteListAccessFromOrigin(const char* sourceOrigin, const char* destinationProtocol, const char* destinationHost, bool allowDestinationSubdomains)
// {
//    SecurityPolicy::addOriginAccessWhitelistEntry(*SecurityOrigin::createFromString(sourceOrigin), destinationProtocol, destinationHost, allowDestinationSubdomains);
// }
//
// void DumpRenderTreeSupportManx::removeWhiteListAccessFromOrigin(const char* sourceOrigin, const char* destinationProtocol, const char* destinationHost, bool allowDestinationSubdomains)
// {
//    SecurityPolicy::removeOriginAccessWhitelistEntry(*SecurityOrigin::createFromString(sourceOrigin), destinationProtocol, destinationHost, allowDestinationSubdomains);
// }
//
// void DumpRenderTreeSupportManx::resetOriginAccessWhiteLists()
// {
//    SecurityPolicy::resetOriginAccessWhitelists();
// }
//
void DumpRenderTreeSupportManx::gcCollectJavascriptObjects()
{
    gcController().garbageCollectNow();
}
//
void DumpRenderTreeSupportManx::gcCollectJavascriptObjectsOnAlternateThread(bool waitUntilDone)
{
    gcController().garbageCollectOnAlternateThreadForDebugging(waitUntilDone);
}

unsigned long DumpRenderTreeSupportManx::gcCountJavascriptObjects()
{
    JSC::JSLock lock(JSC::SilenceAssertionsOnly);
    return JSDOMWindow::commonJSGlobalData()->heap.objectCount();
}

// void DumpRenderTreeSupportManx::layoutFrame(Frame* frame)
// {
//    Frame* coreFrame = core(frame);
//    if (!coreFrame)
//        return;
//
//    FrameView* view = coreFrame->view();
//    if (!view)
//        return;
//
//    view->layout();
// }
//
//// For testing fast/viewport.
// void DumpRenderTreeSupportManx::dumpConfigurationForViewport(WebKitWebView* webView, gint deviceDPI, gint deviceWidth, gint deviceHeight, gint availableWidth, gint availableHeight)
// {
//    g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
//
//    ViewportArguments arguments = webView->priv->corePage->mainFrame()->document()->viewportArguments();
//    ViewportAttributes attrs = computeViewportAttributes(arguments, /* default layout width for non-mobile pages */ 980, deviceWidth, deviceHeight, deviceDPI, IntSize(availableWidth, availableHeight));
//    restrictMinimumScaleFactorToViewportSize(attrs, IntSize(availableWidth, availableHeight));
//    restrictScaleFactorToInitialScaleIfNotUserScalable(attrs);
//    fprintf(stdout, "viewport size %dx%d scale %f with limits [%f, %f] and userScalable %f\n", static_cast<int>(attrs.layoutSize.width()), static_cast<int>(attrs.layoutSize.height()), attrs.initialScale, attrs.minimumScale, attrs.maximumScale, attrs.userScalable);
// }
//
// void DumpRenderTreeSupportManx::clearOpener(Frame* frame)
// {
//    Frame* coreFrame = core(frame);
//    if (coreFrame)
//        coreFrame->loader()->setOpener(0);
// }
//
// unsigned int DumpRenderTreeSupportManx::workerThreadCount()
// {
// #if ENABLE(WORKERS)
//    return WebCore::WorkerThread::workerThreadCount();
// #else
//    return 0;
// #endif
// }
//
// bool DumpRenderTreeSupportManx::findString(WebKitWebView* webView, const char* targetString, WebKitFindOptions findOptions)
// {
//    return core(webView)->findString(String::fromUTF8(targetString), findOptions);
// }
//
// double DumpRenderTreeSupportManx::defaultMinimumTimerInterval()
// {
//    return Settings::defaultMinDOMTimerInterval();
// }
//
void DumpRenderTreeSupportManx::setMinimumTimerInterval(WebView* webView, double interval)
{
    // core(webView)->settings()->setMinDOMTimerInterval(interval);
    // webView->frame()->settings()->setMinDoMTimerInterval(interval);
}

// static void modifyAccessibilityValue(AtkObject* axObject, bool increment)
// {
//    if (!axObject || !WEBKIT_IS_ACCESSIBLE(axObject))
//        return;
//
//    AccessibilityObject* coreObject = webkitAccessibleGetAccessibilityObject(WEBKIT_ACCESSIBLE(axObject));
//    if (!coreObject)
//        return;
//
//    if (increment)
//        coreObject->increment();
//    else
//        coreObject->decrement();
// }
//
// void DumpRenderTreeSupportManx::incrementAccessibilityValue(AtkObject* axObject)
// {
//    modifyAccessibilityValue(axObject, true);
// }
//
// void DumpRenderTreeSupportManx::decrementAccessibilityValue(AtkObject* axObject)
// {
//    modifyAccessibilityValue(axObject, false);
// }
//
// CString DumpRenderTreeSupportManx::accessibilityHelpText(AtkObject* axObject)
// {
//    if (!axObject || !WEBKIT_IS_ACCESSIBLE(axObject))
//        return CString();
//
//    AccessibilityObject* coreObject = webkitAccessibleGetAccessibilityObject(WEBKIT_ACCESSIBLE(axObject));
//    if (!coreObject)
//        return CString();
//
//    return coreObject->helpText().utf8();
// }
//
// void DumpRenderTreeSupportManx::setAutofilled(JSContextRef context, JSValueRef nodeObject, bool autofilled)
// {
//    JSC::ExecState* exec = toJS(context);
//    Element* element = toElement(toJS(exec, nodeObject));
//    if (!element)
//        return;
//    HTMLInputElement* inputElement = element->toInputElement();
//    if (!inputElement)
//        return;
//
//    inputElement->setAutofilled(autofilled);
// }
//
// void DumpRenderTreeSupportManx::setValueForUser(JSContextRef context, JSValueRef nodeObject, JSStringRef value)
// {
//    JSC::ExecState* exec = toJS(context);
//    Element* element = toElement(toJS(exec, nodeObject));
//    if (!element)
//        return;
//    HTMLInputElement* inputElement = element->toInputElement();
//    if (!inputElement)
//        return;
//
//    size_t bufferSize = JSStringGetMaximumUTF8CStringSize(value);
//    GOwnPtr<char> valueBuffer(static_cast<char*>(g_malloc(bufferSize)));
//    JSStringGetUTF8CString(value, valueBuffer.get(), bufferSize);
//    inputElement->setValueForUser(String::fromUTF8(valueBuffer.get()));
// }
//
// void DumpRenderTreeSupportManx::rectangleForSelection(Frame* frame, cairo_rectangle_int_t* rectangle)
// {
//    Frame* coreFrame = core(frame);
//    if (!coreFrame)
//        return;
//
//    IntRect bounds = enclosingIntRect(coreFrame->selection()->bounds());
//    rectangle->x = bounds.x();
//    rectangle->y = bounds.y();
//    rectangle->width = bounds.width();
//    rectangle->height = bounds.height();
// }
//
// bool DumpRenderTreeSupportManx::shouldClose(Frame* frame)
// {
//    Frame* coreFrame = core(frame);
//    if (!coreFrame)
//        return true;
//    return coreFrame->loader()->shouldClose();
// }
//
// void DumpRenderTreeSupportManx::scalePageBy(WebKitWebView* webView, float scaleFactor, float x, float y)
// {
//    core(webView)->setPageScaleFactor(scaleFactor, IntPoint(x, y));
// }
//
// void DumpRenderTreeSupportManx::resetGeolocationClientMock(WebKitWebView* webView)
// {
// #if ENABLE(GEOLOCATION)
//    GeolocationClientMock* mock = static_cast<GeolocationClientMock*>(GeolocationController::from(core(webView))->client());
//    mock->reset();
// #endif
// }
//
// void DumpRenderTreeSupportManx::setMockGeolocationPermission(WebKitWebView* webView, bool allowed)
// {
// #if ENABLE(GEOLOCATION)
//    GeolocationClientMock* mock = static_cast<GeolocationClientMock*>(GeolocationController::from(core(webView))->client());
//    mock->setPermission(allowed);
// #endif
// }
//
// void DumpRenderTreeSupportManx::setMockGeolocationPosition(WebKitWebView* webView, double latitude, double longitude, double accuracy)
// {
// #if ENABLE(GEOLOCATION)
//    GeolocationClientMock* mock = static_cast<GeolocationClientMock*>(GeolocationController::from(core(webView))->client());
//
//    double timestamp = g_get_real_time() / 1000000.0;
//    mock->setPosition(GeolocationPosition::create(timestamp, latitude, longitude, accuracy));
// #endif
// }
//
// void DumpRenderTreeSupportManx::setMockGeolocationError(WebKitWebView* webView, int errorCode, const char* errorMessage)
// {
// #if ENABLE(GEOLOCATION)
//    GeolocationClientMock* mock = static_cast<GeolocationClientMock*>(GeolocationController::from(core(webView))->client());
//
//    GeolocationError::ErrorCode code;
//    switch (errorCode) {
//    case PositionError::PERMISSION_DENIED:
//        code = GeolocationError::PermissionDenied;
//        break;
//    case PositionError::POSITION_UNAVAILABLE:
//    default:
//        code = GeolocationError::PositionUnavailable;
//        break;
//    }
//
//    mock->setError(GeolocationError::create(code, errorMessage));
// #endif
// }
//
// int DumpRenderTreeSupportManx::numberOfPendingGeolocationPermissionRequests(WebKitWebView* webView)
// {
// #if ENABLE(GEOLOCATION)
//    GeolocationClientMock* mock = static_cast<GeolocationClientMock*>(GeolocationController::from(core(webView))->client());
//    return mock->numberOfPendingPermissionRequests();
// #endif
// }
//
// void DumpRenderTreeSupportManx::setHixie76WebSocketProtocolEnabled(WebKitWebView* webView, bool enabled)
// {
// #if ENABLE(WEB_SOCKETS)
//    core(webView)->settings()->setUseHixie76WebSocketProtocol(enabled);
// #else
//    UNUSED_PARAM(webView);
//    UNUSED_PARAM(enabled);
// #endif
// }
//
// void DumpRenderTreeSupportManx::setPageCacheSupportsPlugins(WebKitWebView* webView, bool enabled)
// {
//    core(webView)->settings()->setPageCacheSupportsPlugins(enabled);
// }
//
// bool DumpRenderTreeSupportManx::elementDoesAutoCompleteForElementWithId(Frame* frame, JSStringRef id)
// {
//    Frame* coreFrame = core(frame);
//    if (!coreFrame)
//        return false;
//
//    Document* document = coreFrame->document();
//    ASSERT(document);
//
//    size_t bufferSize = JSStringGetMaximumUTF8CStringSize(id);
//    GOwnPtr<char> idBuffer(static_cast<char*>(g_malloc(bufferSize)));
//    JSStringGetUTF8CString(id, idBuffer.get(), bufferSize);
//    Node* coreNode = document->getElementById(String::fromUTF8(idBuffer.get()));
//    if (!coreNode || !coreNode->renderer())
//        return false;
//
//    HTMLInputElement* inputElement = static_cast<HTMLInputElement*>(coreNode);
//    if (!inputElement)
//        return false;
//
//    return inputElement->isTextField() && !inputElement->isPasswordField() && inputElement->shouldAutocomplete();
// }
//
// JSValueRef DumpRenderTreeSupportManx::computedStyleIncludingVisitedInfo(JSContextRef context, JSValueRef nodeObject)
// {
//    JSC::ExecState* exec = toJS(context);
//    if (!nodeObject)
//        return JSValueMakeUndefined(context);
//
//    JSValue jsValue = toJS(exec, nodeObject);
//    if (!jsValue.inherits(&JSElement::s_info))
//        return JSValueMakeUndefined(context);
//
//    JSElement* jsElement = static_cast<JSElement*>(asObject(jsValue));
//    Element* element = jsElement->impl();
//    RefPtr<CSSComputedStyleDeclaration> style = CSSComputedStyleDeclaration::create(element, true);
//    return toRef(exec, toJS(exec, jsElement->globalObject(), style.get()));
// }
//
// void DumpRenderTreeSupportManx::deliverAllMutationsIfNecessary()
// {
// #if ENABLE(MUTATION_OBSERVERS)
//    WebKitMutationObserver::deliverAllMutations();
// #endif
// }
//
// void DumpRenderTreeSupportManx::setDomainRelaxationForbiddenForURLScheme(bool forbidden, const char* urlScheme)
// {
//    SchemeRegistry::setDomainRelaxationForbiddenForURLScheme(forbidden, String::fromUTF8(urlScheme));
// }
